<template>
	<view class="container">
		<view class="title">预约系统</view>
		<view class="form-group">
			<label>预约日期：</label>
			<picker mode="date" :value="date" @change="onDateChange">
				<view class="picker">{{ date }}</view>
			</picker>
		</view>
		<view class="form-group">
			<label>预约时间：</label>
			<picker mode="time" :value="time" @change="onTimeChange">
				<view class="picker">{{ time }}</view>
			</picker>
		</view>
		<view class="form-group">
			<label>姓名：</label>
			<input type="text" v-model="name" placeholder="请输入姓名" />
		</view>
		<view class="form-group">
			<label>证件类型：</label>
			<picker mode="selector" :range="idTypes" @change="onIdTypeChange">
				<view class="picker">{{ idTypes[idTypeIndex] }}</view>
			</picker>
		</view>
		<view class="form-group">
			<label>证件号码：</label>
			<input type="text" v-model="idNumber" placeholder="请输入证件号码" />
		</view>
		<view class="form-group">
			<label>手机号码：</label>
			<input type="number" v-model="phone" placeholder="请输入手机号码" />
		</view>
		<view class="form-group">
			<label>同行人数：</label>
			<input class="people" type="number" v-model.number="companions" placeholder="请输入同行人数" />
		</view>
		<view>
			<button @click="addMember" class="add">添加同行人</button>
		</view>
		<button @click="submitReserve">提交预约</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

<<<<<<< HEAD
				date: '2024-07-17',
				time: '09:00:00',
=======
				date: '2024-7-16',
				time: '12:00:00',
>>>>>>> fd41927a8cc64a1a69275b918e5e2579087a90c4
				name: '',
				idTypes: ['身份证', '护照', '其他'],
				idTypeIndex: 0,
				idNumber: '',
				phone: '',
				companions: '',
			};
		},
		methods: {
			
			addMember() {
				if (this.members.length < this.companions) {
					this.members.push({
						name: '',
						idType: '',
						idNumber: '',
						phoneNumber: ''
					});
				} else {
					uni.showToast({
						title: '已达到预约人数上限',
						icon: 'none'
					});
				}
			},
			removeMember(index) {
				if (this.members.length > 1) { // 假设至少保留一个成员  
					this.members.splice(index, 1);
					this.updateTotalPeople();
				}
			},
			updateTotalPeople() {
				this.totalPeople = this.members.length;
			},
			
			
			onDateChange(e) {
				this.date = e.detail.value;
			},
			onTimeChange(e) {
				this.time = e.detail.value;
			},
			onIdTypeChange(e) {
				this.idTypeIndex = e.detail.value;
			},
			submitReserve() {
				const userData = {
					date: this.date,
					time: this.time,
					name: this.name,
					idType: this.idTypes[this.idTypeIndex],
					idNumber: this.idNumber,
					phone: this.phone,
					companions: this.companions,
				};
				uni.setStorage({
					key: 'userData',
					data:JSON.stringify(userData),
					success:function(){
						 console.log('数据存储成功');
						 uni.navigateTo({
						 	url:'/pages/successfulApointment/successfulApointment'
						 })
					}
				})
			},
		},
	}
</script>

<style>
	.container {
		padding: 20px;
	}

	.title {
		font-size: 18px;
		font-weight: bold;
		margin-bottom: 20px;
	}

	.form-group {
		margin-bottom: 15px;
	}

	.form-group label {
		display: block;
		margin-bottom: 5px;
	}

	.picker {
		padding: 10px;
		border: 1px solid #ccc;
		border-radius: 5px;
	}
	.people {
		border: 2px;
		border-color: #f3f5f9;
		border-style: solid;
		background-color: #f3f5f9;
		border-radius: 7px;
		width: 100%;
	}
</style>